import { contextBridge, ipcRenderer } from "electron";
import type { MultScreenSender,MultScreenListener } from "@/types/mult-preload-type";
import { BROADCAST, MultAPISender,MultAPIListener, OPEN_MULT, SEND_MESSAGE_TO_ALL, TO_VIEW } from "@/ipc-event-names/mult";

/**
 * 多屏消息发送者
 */
const senderFuncs: MultScreenSender = {
    openMult: () => ipcRenderer.send(OPEN_MULT),
    sendMessageToAll: (message) => ipcRenderer.send(SEND_MESSAGE_TO_ALL, message),
};

/**
 * 多屏消息监听者
 */
const listenerFuncs: MultScreenListener = {
    onBroadcast: (callback) => ipcRenderer.on(BROADCAST, (_, message) => callback(message)),
    toView: (callback) => ipcRenderer.on(TO_VIEW, (_, message) => callback(message))
};

contextBridge.exposeInMainWorld(MultAPISender, senderFuncs);
contextBridge.exposeInMainWorld(MultAPIListener, listenerFuncs);

